/**
 * Created by Administrator on 2015/12/29.
 */
"use strict";
var _ = require('underscore');
var F = require('../../../common/function');
var mysql = require('../../../common/mysql');
var C = require('../../../config/index');
var _o2oServiceApi = require('../../../common/o2oServiceApi');
var o2oServiceApi = new _o2oServiceApi;

module .exports.addUserInfo = function *(orderResult){
    if(orderResult['result'].length>0){
        let uids =[];
        for(let item of orderResult['result']){
            uids.push(item.uid);
        }
        uids = _.uniq(uids);
        let  userInfo  =yield  mysql.query("select uid,nickname,mobile from mh_user where uid in ("+uids.join()+")");
        //console.log(uids);
        //console.log(userInfo);
        for (let i of orderResult['result']){
            for (let j of userInfo){
                if(i.uid == j.uid){
                    i.mobile = j.mobile;
                    i.name = j.nickname;
                    break;
                }
            }
        }
    }

}

module .exports.getPayment =function*(orderResult){
    if(!_.isEmpty(orderResult['result'])){
        orderResult['result']['real_pay_price'] =0;
        orderResult['result']['coupon_pay_price']=0;
        if(orderResult['result']['status'] ==1){
            //查询实际支付金额
            let payway = yield  mysql.queryOne("select price from mh_order_payway where order_id =?",[orderResult['result']['orderid']]);
            if(payway && payway['price']){
                orderResult['result']['real_pay_price'] = parseFloat(payway['price']);
                orderResult['result']['coupon_pay_price'] = parseFloat(orderResult['result']['totalPrice'])- orderResult['result']['real_pay_price'];
            }
        }
    }
}